using System;
using System.Collections.Generic;
using System.Text;
using PokerLearner;

namespace PokerLearner.Poker
{
	public class PokerManager
	{
		#region Players

		private List<Player> players;

		public List<Player> Players
		{
			get { return players; }
		}

		#endregion

		#region Player Control

		virtual public void AddPlayer(Player player)
		{
			players.Add(player);

			// Call the delegate if any handlers registered
			if (PlayerAdded != null)
			{
				PlayerAdded(this, new PlayerEventArgs(player));
			}
		}

		virtual public void RemovePlayer(Player player)
		{
			players.Remove(player);

			if (PlayerRemoved != null)
			{
				PlayerRemoved(this, new PlayerEventArgs(player));
			}
		}

		public void RemoveAllPlayers()
		{
			if (PlayerRemoved != null)
			{
				foreach (Player player in players)
				{
					PlayerRemoved(this, new PlayerEventArgs(player));
				}
			}
			players.Clear();
		}

		

		#endregion

		#region Round

		private Round round;
		public Round Round
		{
			get { return round; }
			protected set 
			{ 
				round = value;
				if (NewRound != null && value != null)
				{
					NewRound(this, null);
				}
			}
		}



		#endregion

		#region Events

		public event EventHandler NewRound;
		public event EventHandler<PlayerEventArgs> PlayerAdded;
		public event EventHandler<PlayerEventArgs> PlayerRemoved;
		public event EventHandler<PlayerEventArgs> DealerChanged;

		#endregion

		#region Constructor

		public PokerManager()
		{
			players = new List<Player>();
		}

		#endregion
	}
}
